// import { mixinDict } from '@/utils/mixin.js'
// mixins: [mixinDict],

import useDictStore from '@/store/modules/dict'
import { useDict, updateApiDict } from '@/utils/dict'
export const mixinDict = {
  data() {
    return {
      // 静态字典
      dictMap: [],

      // 动态字典
      dictApiMap: [],

      dict: {},
    }
  },

  created() {
    // 获取静态字典,通过"系统管理/字典管理"的字典值
    if (this.dictMap.length > 0) {
      const dictList = this.useDict(...this.dictMap)
      for (let f1 in dictList) {
        this.dict[f1] = dictList[f1]
      }
    }

    // 动态字典,通过api接口做为字典值使用
    const dictApiList = this.useApiDict(this.dictApiMap)
    for (let f1 in dictApiList) {
      this.dict[f1] = dictApiList[f1]
    }
  },
  methods: {
    // 字典值翻译
    dictToName(dictType, value) {
      let dict = useDictStore().getDict(dictType)
      if (!dict) {
        useDict(dictType)
        return ''
      }

      const ss = dict.find((item) => {
        return item.value == value
      })
      return ss && ss.label
    },

    updateApiDict(dictType) {
      updateApiDict(dictType).then((res) => {
        this.dict[dictType] = res.data
      })
    },
  },
}
